package com.zhc.dejingapi.controller;


import com.zhc.dejingapi.entity.vo.EquipmentStsVo;
import com.zhc.dejingapi.pojo.param.QingDataCommResult;
import com.zhc.dejingapi.pojo.param.QingEquipmentParam;
import com.zhc.dejingapi.service.IQingEquipmentService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhc
 * @since 2024-08-07
 */
@RestController
@RequestMapping("/qingequip")
@CrossOrigin
public class QingEquipmentController {

    private final IQingEquipmentService qingEquipmentService;

    public QingEquipmentController(IQingEquipmentService qingEquipmentService1) {
        this.qingEquipmentService = qingEquipmentService1;
    }

    @PostMapping("/getEquipmentSts")
    public List<List<EquipmentStsVo>> getEquipmentSts() {
        return qingEquipmentService.getEquipmentSts();
    }
    @PostMapping("/getEquipmentStsList")
    public List<EquipmentStsVo> getEquipmentStsList() {
        return qingEquipmentService.getEquipmentStsList();
    }

    @PostMapping("/addequip")
    public QingDataCommResult addEquip(@RequestHeader(name = "apiKey") String apiKey,@RequestBody QingEquipmentParam eqParam) throws IllegalAccessException {


        String strApiKey="B82ADA3F119D42A0B3AC237FDD6C40960A9065EB402A4D73B4D227AF15EF6D88";

        if(apiKey.equals(strApiKey)){
            return qingEquipmentService.AddEquipment(eqParam);
        }
        else {
            QingDataCommResult result=new QingDataCommResult();
            result.setErrCode(-10010);
            result.setErrMsg("appKey出错，无法继续！");
            return result;
        }

    }
    @PostMapping("/updequip")
    public QingDataCommResult updEquip(@RequestHeader(name = "apiKey") String apiKey,
                                       @RequestBody QingEquipmentParam eqParam) throws IllegalAccessException {

        String strApiKey="B82ADA3F119D42A0B3AC237FDD6C40960A9065EB402A4D73B4D227AF15EF6D88";

        if(apiKey.equals(strApiKey)){
            return qingEquipmentService.UpdEquipment(eqParam);
        }
        else {
            QingDataCommResult result=new QingDataCommResult();
            result.setErrCode(-10010);
            result.setErrMsg("appKey出错，无法继续！");
            return result;
        }

    }

    @PostMapping("/selectEq")
    public List<String> selectEq() {
        return qingEquipmentService.selectEq();
    }





}
